<?php

class RequestDispatcher {
	
	private $requestMapping = array(
		'fetch_categories' => 'FetchCategoriesRequest',
		'fetch_topics' => 'FetchTopicsRequest',
		'fetch_users' => 'FetchUsersRequest',
		'insert_topic' => 'InsertTopicRequest',
		'user_login' => 'UserLoginRequest',
		'user_register' => 'UserRegisterRequest',
		// 'update_topic' => 'UpdateTopicRequest',
		// 'delete_topic' => 'DeleteTopicRequest',
		'insert_vote' => 'InsertVoteRequest',
		'revoke_vote' => 'RevokeVoteRequest'
	);
	
	/**
	 * Invokes request.
	 *
	 * @param String[] $get
	 * @return String request class name
	 */
	public function processGet($get) {
		/*
		http://localhost/~phudy/jsugvoting/?request=fetch_topics
		*/
		if(!isset($get['request']) || $get['request'] == '') {
			throw new Exception("No request type provided!");
		}
		
		$requestType = $get['request'];
		if(!isset($this->requestMapping[$requestType])) {
			throw new Exception("ERROR: Invalid request type: [" . $requestType . "]!");
		}
		
		return $this->requestMapping[$requestType];
	}
}

?>